package com.example.common.core.domain;

import com.example.common.core.enums.ResultCode;
import lombok.Data;
import org.springframework.validation.annotation.Validated;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 23050
 * @version 1.0
 * @description: 列表查询响应类
 * @date 2025/2/16 20:11
 */
@Data
public class TableDataInfo {

    private int code; //响应码
    private String msg; //响应信息
    private long total; //数据总数
    private List<?> rows; //数据内容

    public TableDataInfo() {
    }

    public TableDataInfo(int code, String msg, long total, List<?> rows) {
        this.code = code;
        this.msg = msg;
        this.total = total;
        this.rows = rows;
    }

    //查出数据为空时返回
    public static TableDataInfo empty(){
        TableDataInfo repData = new TableDataInfo();
        repData.setCode(ResultCode.SUCCESS.getCode());
        repData.setRows(new ArrayList<>());
        repData.setMsg(ResultCode.SUCCESS.getMsg());
        repData.setTotal(0);
        return repData;
    }


    //查询成功返回
    public static TableDataInfo success(List<?> list,long total){
        TableDataInfo repData = new TableDataInfo();
        repData.setCode(ResultCode.SUCCESS.getCode());
        repData.setRows(list);
        repData.setMsg(ResultCode.SUCCESS.getMsg());
        repData.setTotal(total);
        return repData;
    }


}
